package com.worldvision.main.util;

import java.io.IOException;
import java.util.Random;

import org.openqa.selenium.WebDriverBackedSelenium;
import org.openqa.selenium.firefox.FirefoxDriver;

//import lib.System.SYS;
//import lib.System.Utility.Report;
//
//import com.sarees.main.util.WebUtil;
import com.thoughtworks.selenium.Selenium;


public class VerifyUtil 
{
	//WebUtil w;
	static Selenium selenium;
	public VerifyUtil()
	{
		//this.w = w;
		selenium  = (new WebDriverBackedSelenium((new FirefoxDriver()),"http:\\www.worldvisionindia.com"));
	}
	//WebUtil w = new WebUtil();
	public static VerifyUtil getVerObj()
	{
		// TODO Auto-generated method stub
		return (new VerifyUtil());
	}
//	public void verifyUserLoggedIn() throws IOException {
//		// TODO Auto-generated method stub
//		if(!selenium.isElementPresent(LOC.lblErrMsg))
//		{
//			Report.passMSG("Testcase passed: verifyUserLoggedIn");
//			return;
//		}	else
//		{
//			Report.failMSG("Testcase failed: verifyUserLoggedIn");
//		}
//		//verifyTrue();
//		//verifyEquals("Error: Sorry, there is no match for that email address and/or password.", selenium.getText("css=div.messageStackError.larger"));
//	}

//	public void verifyUserNotLoggedIn(Object iNVALIDUSRMSG) throws IOException 
//	{
//		//fix trhe bug
//		// TODO Auto-generated method stub
//		if(selenium.isElementPresent(LOC.lblErrMsg) && selenium.getText(LOC.lblErrMsg).contains((CharSequence)DATA.INVALIDUSRMSG))
//		{
//			Report.passMSG("Testcase passed: verifyUserNotLoggedIn");
//						
//		}
//		else
//		{
//			Report.failMSG("Testcase failed: verifyUserNotLoggedIn");
//		}
//	}

	

//	public void verifyUsrReg(String uName) throws IOException {
//		// TODO Auto-generated method stub
//		if(selenium.isElementAndTextPresent(LOC.REGMSG,DATA.REGMSG))
//		{
//			if(selenium.isTextPresent(uName))
//			{
//				Report.passMSG("User regestration passed.");
//			}
//			else
//			{
//				Report.failMSG("User name not matching... with given main.");
//			}
//		}
//		else
//		{
//			Report.failMSG("User not registed......");
//		}
//	}
	
//	public void verifyItemFound(String dEFAULTITEM) {
//		// TODO Auto-generated method stub
//		if(selenium.isElementAndTextPresent(LOC.SEARCHRESULTS,dEFAULTITEM ))
//		{
//			Report.passMSG("Search results find for search item "+dEFAULTITEM);
//			
//		}
//		else
//		{
//			Report.failMSG("Search result not found for the item "+dEFAULTITEM);
//		}
//	}
//	public void verifyResFound() {
//		// TODO Auto-generated method stub
//		if(selenium.isElementPresent(LOC.SEARCHRESULTS ))
//		{
//			Report.passMSG("Search results find");
//			
//		}
//		else
//		{
//			Report.failMSG("Search result not found");
//		}
//	}
//	public void verifyItemAdded(String dEFAULTITEM) {
//		// TODO Auto-generated method stub
//		if(SystemUtil.isCellWithTextPresentInColumn(LOC.BASKETTABLEID, dEFAULTITEM, DATA.ITEMHEADER))
//		{
//			Report.passMSG(null);
//		}
//		else
//		{
//			Report.failMSG(null);
//		}
//	}
//	public void verifyItemQuanity(String dEFAULTITEM2, String qUANTITYTOUPDATE) {
//		// TODO Auto-generated method stub
//		if(SystemUtil.isCellWithTextPresentInColumn(LOC.BASKETTABLEID, qUANTITYTOUPDATE, DATA.QTYHEADER))
//		{
//			Report.passMSG(null);
//		}
//		else
//		{
//			Report.failMSG(null);
//		}
//	}
	
	public void verifyItemTotal(String tableLocator,String value,String columnHeader,String item) {
		// TODO Auto-generated method stub
		if(SystemUtil.isCellWithTextPresent(tableLocator, value, columnHeader,item))
		{
			Report.passMSG(null);
		}
		else
		{
			Report.failMSG(null);
		}
	}
//	public void verifyGrandTotal(String gRANDQTY) {
//		// TODO Auto-generated method stub
//		if(selenium.isTextPresent(DATA.GRANDTOTALSUFFIX+gRANDQTY)){
//			Report.passMSG(null);
//		}
//		else
//		{
//			Report.failMSG(null);
//		}
//	}
	public void verifyHeader(String locator, String hDRQTY, String hDRPRICE) {
		// TODO Auto-generated method stub
		String qty;
		String price;
		String[] temp;
		if(selenium.isElementPresent(locator))
		{
			if(selenium.getText(locator)!="")
			{
				temp = selenium.getText(locator).split("-");
				if(temp[0].trim().contains(hDRQTY))
				{
					Report.passMSG("Quantity of Header is as expected.");
				}
				else
					Report.failMSG("Quantity of Header is not as expected.");
				//check the price in header
				if(temp.length<2)
				{
					Report.failMSGandAssert("Price is not shown in Header");
				}
				if(temp[1].trim().contains(hDRPRICE))
				{
					Report.passMSG("Price of item in header is as expected.");
				}
				else
					Report.failMSG("Price of item in Header is not as expected.");
			}
		}
	}
	public void verifyFTRTotal(String fTR, String fTRPRICE) {
		// TODO Auto-generated method stub
	
		if(selenium.getText(fTR).contains(fTRPRICE))
		{
			Report.passMSG("Price of item in footer is as expected.");
		}
		else
			Report.failMSG("Price of item in footer is not as expected.");
	}
//	public void verifyText(String cHKCNFMSG, String vERCNFMSG) {
//		// TODO Auto-generated method stub
//		if(selenium.isElementAndTextContains(cHKCNFMSG, vERCNFMSG))
//		{
//			Report.passMSG("Checkout message is as expected.");
//		}
//		else
//			Report.failMSG("Checkout message  is not as expected.");
//		}
//	public void verifyOrderItemAdded(String dEFAULTITEM2) {
//		// TODO Auto-generated method stub
//		if(SystemUtil.isCellWithTextPresentInColumn(LOC.ORDERID, dEFAULTITEM2, DATA.ITEMHEADER))
//		{
//			Report.passMSG(null);
//		}
//		else
//		{
//			Report.failMSG(null);
//		}
//	
//	}
	public void verifyOrderTotal(String gRANDQTY2) {
		// TODO Auto-generated method stub
		
	}
}
